/*
 * timer0.c
 *
 *  Created on: 2015-03-10
 *      Author: root
 */
#include "timer1.h"
#include "definitions.h"
#include "uart.h"


int gtimer1Flags = 0;
unsigned long ulPeriod;

void initTimer1(void)
{
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
	//set timer period: 40MHz/10/2 = 2MHz = 0.5us
	//for 1000us = 1ms use Div by 0.1 and then 4, 40MHz / 0.1 / 4 = 1ms
	ROM_TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC);
	ulPeriod = (ROM_SysCtlClockGet() / 1 / 1);		//for 1s
	ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, ulPeriod - 1);

	//Timer interrupt setup
	ROM_TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
	ROM_TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
	ROM_IntEnable(INT_TIMER1A);
	ROM_TimerEnable(TIMER1_BASE, TIMER_A);
	bt_UARTsend("Timer1 Loaded\r\n");

	//specifically for adc
	ROM_TimerControlTrigger(TIMER1_BASE, TIMER_A, true);
	bt_UARTsend("Timer1 Trigger for ADC set\r\n");
}

void timer1Handler(void)
{
	//reset counter value back to ulPeriod
	ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, ulPeriod-1);

	//clear interrupt
	ROM_TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);

	//bt_UARTsend("timer\n");
	//ROM_GPIOPinWrite(GPIO_PORTF_BASE, redled, gFlip);

	//fire off adc interrupt for temperature reading
	//ADCProcessorTrigger(ADC0_BASE, 0);
}

void timer1Setup(void)
{

}
